package com.ktjiaoyu.service.impl;

import com.ktjiaoyu.entity.SysRole;
import com.ktjiaoyu.mapper.SysRoleMapper;
import com.ktjiaoyu.service.SysRoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysRoleServiceImpl implements SysRoleService {
    private static final Logger LOGGER= LoggerFactory.getLogger(SysUserServiceImpl.class);

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public List<SysRole> findAll() throws Exception {
        try {
            return sysRoleMapper.getAll();
        }catch (Exception e){
            LOGGER.error("执行SysRoleServiceImpl.findAll()方法出现异常。",e);
            throw e;
        }
    }

    @Override
    public SysRole findById(Long id) {
        try {
            return sysRoleMapper.findById(id);
        }catch (Exception e){
            LOGGER.error("执行SysRoleServiceImpl.findById()方法出现异常。",e);
            throw e;
        }
    }

    @Override
    public SysRole findByCode(String code) {
        try {
            return sysRoleMapper.getByCode(code);
        }catch (Exception e){
            LOGGER.error("执行SysRoleServiceImpl.getByCode()方法出现异常。",e);
            throw e;
        }
    }

    @Override
    public int insertRole(SysRole sysRole) {
        try {
            return sysRoleMapper.insert(sysRole);
        }catch (Exception e){
            LOGGER.error("执行SysRoleServiceImpl.insert(SysRole)方法出现异常。",e);
            throw e;
        }
    }

    @Override
    public int updateRole(SysRole sysRole) {
        try {
            return sysRoleMapper.update(sysRole);
        }catch (Exception e){
            LOGGER.error("执行SysRoleServiceImpl.update(SysRole)方法出现异常。",e);
            throw e;
        }
    }

    @Override
    public int deleteRole(Long id) {
        try {
            return sysRoleMapper.delete(id);
        }catch (Exception e){
            LOGGER.error("执行SysRoleServiceImpl.delete(Long)方法出现异常。",e);
            throw e;
        }
    }
}
